/*************************************************************************
	> File Name: 3.最长公共子串.cpp
	> Author: 
	> Mail: 
	> Created Time: 
 ************************************************************************/
#include <iostream>
#include <vector>
using namespace std;

string search(const string &s1, const string &s2) {
    int start = 0;
    int max_len = 0;
    int len1 = s1.size(), len2 = s2.size();
    vector<vector<int> > count(len1 + 1, vector<int>(len2 + 1));
    for (int i = 1; i <= len1; i++) {
        for (int j = 1; j <= len2; j++) {
            if (s1[i - 1] == s2[j - 1]) {
                count[i][j] = count[i - 1][j - 1] + 1;
            }
            if (count[i][j] > max_len) {
                max_len = count[i][j];
                start = i - max_len;
            }
        }
    }
    return s1.substr(start, max_len);
}

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    if (s1.size() > s2.size()) swap(s1, s2);
    cout << search(s1, s2) << endl;
    return 0;
}
